package cn.ming.wfchat.app.viewholder;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import cn.ming.wfchat.app.AppService;
import cn.ming.wfchat.kit.R;
import cn.ming.wfchat.kit.annotation.ExtContextMenuItem;
import cn.ming.wfchat.kit.contact.pick.ChooseContactActivity;
import cn.ming.wfchat.kit.conversation.ext.core.ConversationExt;
import cn.wildfirechat.model.Conversation;
import cn.wildfirechat.remote.ChatManager;

//名片
public class CardExt extends ConversationExt {

    /**
     * @param containerView 扩展view的container
     * @param conversation
     */
    @ExtContextMenuItem
    public void pickCard(View containerView, Conversation conversation) {
        Intent intent = new Intent(activity, ChooseContactActivity.class);
        startActivityForResult(intent, 103);
    }

    @Override
    public int priority() {
        return 100;
    }

    @Override
    public int iconResId() {
        return R.mipmap.ic_func_mingpian;
    }

    @Override
    public String title(Context context) {
        return "名片";
    }

    @Override
    public String contextMenuTitle(Context context, String tag) {
        return title(context);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == activity.RESULT_OK) {
            if (requestCode == 103) {
                if (data != null) {
//                    messageViewModel.sendCard(conversation,
//                            ChatManager.Instance().getUserInfo(data.getStringExtra("userid"), false));
                    AppService.Instance().sendVisitingCard(data.getStringExtra("userid"), conversation.target, conversation.type.getValue() + "", new AppService.SendCodeCallback() {
                        @Override
                        public void onUiSuccess() {
                            ChatManager.showToast("发送成功");
                        }

                        @Override
                        public void onUiFailure(String msg) {
                            ChatManager.showToast(msg);
                        }
                    });
                }

            }
        }
    }
}
